if( selenium.browserbot.getCurrentWindow().showModalDialog ) {
	selenium.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures ) {
		var parentWin = selenium.browserbot.getCurrentWindow();
		
		if( typeof(parentWin._modalRetVal) == 'undefined' || parentWin._modalRetVal == 'N.A.' ) {
			// first click, we should open the modal dailog with a 'normal' way
			
			// because the format of parameter 'sFeatures' for showModalDialog() and for window.open() is different,
			// some 'translation' job should be down here
			/*if( typeof(sFeatures) != 'undefined' && sFeatures != null ) {
				sFeatures = sFeatures.replace( ';', ',' );
				...
			}*/
			
			// open the child page, and pass the arguments to it
			var childWin = parentWin.open( sURL, 'modal', sFeatures );
			childWin.dialogArguments = vArguments;
			selenium.browserbot.openedWindows['modal'] = childWin;
			
			// if _modalRetVal is not defined, do some fix to get the parent window ready to get return value
			if( typeof(parentWin._modalRetVal) == 'undefined' ) {
				// define _modalRetVal and set it to 'N.A.'
				parentWin._modalRetVal = 'N.A.';
				
				// Complex values and arrays are passed by reference. Once the window gets closed the reference
				// is lost. To avoid this we will store deep copy (clone) rather than just the value.
				parentWin._cloneObject = function( obj ) {
					if( typeof(obj) != 'object' || obj == null ) {
						return obj;
					}
					try {
						var temp = new obj.constructor(obj);
						for( var mem in temp ) {
							temp[mem] = parentWin._cloneObject( obj[mem] );
						}
						return temp;
					} catch (e) {
						return obj;
					}
				};
			
				// Injecting a function to be called by the popup window while saving the return value.
				parentWin._getModalRetVal = function( val ) {
					if( parentWin._modalRetVal == 'N.A.' ) {
						parentWin._modalRetVal = parentWin._cloneObject(val);
					}
				};
			}
		} else {
			// second click, we just need to get the return value from variable _modalRetVal
			
			var temp = parentWin._modalRetVal;
			parentWin._modalRetVal = 'N.A.';
			return temp;
		}
		
	};
}